define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'monitor/department/index',
                    add_url: 'monitor/department/add',
                    edit_url: 'monitor/department/edit',
                    del_url: 'monitor/department/del',
                    multi_url: 'monitor/department/multi',                    
                    table: 'wechat_department',
                }
            });

            var table = $("#table");
            var parent_data = Config.parent_data;
            var parent_data_arr = parent_data;
            var item = {0:'顶级'};
            parent_data_arr[0] = '顶级';
            delete parent_data_arr['-1'];
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'order',
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'),operate:'LIKE',placeholder: __('模糊查询')},
                        {field: 'parentid', title: __('Parentid'),searchList:parent_data_arr,operate:'LIKE %...%'},
                        {field: 'order', title: __('Order')},                      
                    ]
                ]
            });

            //  获取最新数据
            $("#get_department").click(function(){
                $.post('/api/ewechat/department',function(json){                    
                    if(json.code == 1){
                        Backend.api.toastr.success(json.msg);
                        table.bootstrapTable('refresh', {});
                    }else{
                        Backend.api.toastr.error(json.msg);
                    }                  
                })
            })
            

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },        
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});